[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
sub(r,s) substitute
Substitute s for leftmost string matched by r in $0, return number of
substitutions made: 0/1.
sub(r,s,t) substitute
Substitute s for leftmost string matched by r in t, return number of
substitutions made: 0/1.
Derive two strings, path and filename, from DOS path\filename string.
Strategy: use pattern to find filename[.ext] at end of string and set
to null string for path, get suffix for filename[.ext].
pathfile == "a:\path1\subpath2\file1.ext";
# characters excluded from filename
exc_c = /[!\x01-\x21."\/\\\[\]:|<>+=;,]/;
# DOS filename.ext pattern
# filename consists of all characters not excluded from proper name
# followed by optional extension of 1 to 3 characters
# followed by end of string
name_pat = /{exc_c}+(.{exc_c}{1,3})?$/;
path = pathfile;
# delete filename.ext at end to leave path
sub(name_pat,"",path);
# get suffix of path in pathfilename
filename = substr(pathfile,1 + length(path));
path ==> "a:\path1\subpath2\"
filename ==> "file1.ext";
See Also:
gsub
substr
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson